public class test2 {
        public static int maxSubArray(int[] nums) {

            int currentSum = nums[0];
            int maxSum = nums[0];


            for (int i = 1; i < nums.length; i++) {

                currentSum = Math.max(nums[i], currentSum + nums[i]);

                maxSum = Math.max(maxSum, currentSum);
            }

            return maxSum;
        }

        public static void main(String[] args) {
            int[] nums1 = {1, -2, 3, 4, -5};
            int[] nums2 = {-1, -3, 7, 8, 5, 1};
            int[] nums3 = {1, -2, 3, -2, 6, 1};

            System.out.println("[1, -2, 3, 4, -5]的最大子数组之和为: " + maxSubArray(nums1));
            System.out.println("[-1, -3, 7, 8, 5, 1]的最大子数组之和为: " + maxSubArray(nums2));
            System.out.println("[1, -2, 3, -2, 6, 1]的最大子数组之和为: " + maxSubArray(nums3));
        }
}
